package com.ruoyi.web.taskSchedule;

import com.ruoyi.eamp.domain.EampMeeting;
import com.ruoyi.eamp.mapper.EampMeetingMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Component
public class MeetingTask {
    @Autowired
    private EampMeetingMapper eampMeetingMapper;
    @Scheduled(cron="0 0/1 *  * * ? ")
    public void updateMeetingStatus(){
        System.out.println(11111);
        Date now=new Date();
        //把未开始改成进行中
        List<EampMeeting> meetingList=eampMeetingMapper.selectNoStartMeeting("0");
//        List<Long> idList=new ArrayList<>();
        for (EampMeeting eve:meetingList) {

            if(eve.getStartDate().before(now)){
                Long meetingId = eve.getMeetingId();
//                idList.add(meetingId);
                eve.setStaus("1");
                eampMeetingMapper.updateEampMeeting(eve);
            }
        }
//        if(idList.size()!=0){
//            int num = eampMeetingMapper.updateBatchEampMeeting(idList);
//        }

        //把进行中改成已结束
        List<EampMeeting> ingList=eampMeetingMapper.selectNoStartMeeting("1");
        for (EampMeeting eve:ingList) {
            if(now.after(eve.getEndDate())){
                eve.setStaus("2");
                eampMeetingMapper.updateEampMeeting(eve);
            }
        }
    }
}
